if(files.cwd().endsWith("脚本")){
    let _require = require;
    require = function(path){
      if(path.startsWith("./")){
        path = path.replace("./","");
      }
      path = files.cwd() + "/gdt_hb/" + path;
      return _require(path);
    }
  }
  
  
  auto.waitFor()
  var utils = require("./utils.js");
  var storage = storages.create("xiangxiangyuedu");
  
//关闭广告弹窗
function closeAdPop(){
    var close = text("pwg_iconClose0").findOne(5000);
    if(close){
        sleep(500);
        utils.realClick(close);
    }
}

//关闭切页广告
function closeSwitchAdPop(){
    var webView= className("android.webkit.WebView").depth(6).findOne(3000);
    if(webView){
        back();
    }
}

function main(){
    var open = utils.launchAppEnhance("链尚微淘");
    if(open){
        console.log("等待进入首页")
        waitForActivity("com.uzmap.pkg.EntranceActivity")
        console.log("进入到首页完毕");
        sleep(2000)
        closeAdPop();
        var 淘宝 = text("淘宝").findOne(5000);
        if(淘宝){
            sleep(500);
            utils.realClick(淘宝);
            sleep(5000);
            var list = textStartsWith("预估收益").find(60000);
            if (list && list.size() > 0) {
                for (var i = 0; i < 2; i++) {
                    if (list) {
                        var item = list[i];
                        if (item) {
                            utils.realClick(item);
                            let progress = (i + 1) * 30;
                            if(progress < 100){
                                utils.updateAppProgress(progress);
                            }                            
                            sleep(5000);
                            back();
                            sleep(3000);
                        }
                    } else {
                        log("查看商品失败");
                    }

                }
            }
            back();            
            sleep(2000);
            var 任务 = text("任务").findOne(2000);
            if(任务){
                utils.realClick(任务);
                closeSwitchAdPop();
                sleep(500);
                var 领取奖励 = text("领取奖励").findOne(30000);
                if(领取奖励){
                    utils.realClick(领取奖励);
                }
            }
            
            
        }
        
        
    }
}

try {
    main();
    utils.updateAppProgress(100);
  } catch (error) {
    toastLog(error);
  }
storage.put("script_running_status", "end");